<?php
# LemurCMS by Alec Gorge
#
#     This file contains the PHP functions used throught the CMS.
#
# updated: Feb. 6, 2009
class themeManager extends functions {
	public $childLookup = false, $childLookup1, $childLookup2,
	$idLookup1, $idLookup1clean, $idLookup2clean, 
	$idLookup2, $idLookup = false, $idLookupClean = false,
	$nav_link, $r, $staticContent, $arrayNavigation,
	$arraySecondaryNavigation= -10, $themeStaticContent,
	$navigation = false, $secondary_navigation = false, $blacklist = array(),
	$hidden = false, $hidden1, $hidden2,
	$hiddenClean = false, $hiddenClean1, $hiddenClean2,$external = array();
	public function __construct ($id = "") {
		$this->id = $id;
		$this->arrayStaticContent();
	}
	public function countNavItems ($nav) {
		if($nav == 'primary') {
			if (empty($this->arrayNavigation))
				$this->arrayNavigation();
			return count($this->arrayNavigation);
		}
		elseif ($nav == 'secondary') {
			if ($this->arraySecondaryNavigation == -10)
				$this->arraySecondaryNavigation();
			return count($this->arraySecondaryNavigation);
		}
	}
	public function arrayStaticContent () {
		if(!isset($GLOBALS['staticContent'])) {
			$sql = "SELECT * FROM ".DBTABLEPREFIX."content_template WHERE template = '".$this->getSetting('Theme')."' ORDER by id";
			$run = $this->db_query($sql)or die($this->db->error());
				$call_info = array_shift( debug_backtrace() );
				$code_line = $call_info['line'];
				$file = array_pop( explode('/', $call_info['file']));
			while($rec = $this->db->fetchAssoc($run)) {
				$r[$rec['name']] = array(
					'id' => $rec['id'],
					'content' => stripslashes($rec['content']),
					'name' => $rec['name'],
					'textOnly' => $rec['textOnly']
				);
			}
			$this->staticContent = $r;
			$GLOBALS['staticContent'] = $r;
		}
		return $GLOBALS['staticContent'];
	}
	public function arrayNavigation($admin = false) {
		if(empty($this->arrayNavigation)) {
				$refs = array();
				$data = array();
				$options = false;
				$list = array();
				$sql = "SELECT parent_id, menutitle, id, options FROM ".DBTABLEPREFIX."content_pages WHERE NOT secondary = 'yes' ORDER by orderingid ";
				$run = $this->db_query($sql)or die($this->db->error());
				while($data = $this->db->fetchAssoc($run)) {
					$options = unserialize(stripcslashes($data['options']));
					$thisref = &$refs[ $data['id'] ];
					if($options['show'] == 'show' || $options == false || $admin == true) {
						$thisref['id'] = $data['id'];
						$thisref['menutitle'] = $data['menutitle'];
						if(!empty($options['external'])) {
							$external[$thisref['id']] = $options['external'];
						}
						if ($data['parent_id'] == 0) {
							$list[$thisref['id']] = &$thisref;
						} else {
							$refs[ $data['parent_id'] ]['children'][ $thisref['id'] ] = &$thisref;
						}
					}
					if($options['show'] !== 'show' && $options !== false) {
						if(empty($options['external']))
							$list5[$data['menutitle']] = $data['id'];
					}
					//var_dump($data, $thisref['id'], $options,$list5,"\n\n");
					$list2[$thisref['id']] = $thisref['menutitle'];
					$list3[$thisref['id']] = $this->make_clean_url($thisref['menutitle']);
					$list4[$thisref['id']] = $data['parent_id'];
				}
				$this->arrayNavigation = $list;
				$this->idLookup1 = $list2;
				$this->idLookup1clean = $list3;
				$this->childLookup1 = $list4;
				$this->hidden1 = $list5;
				$this->external = $this->external + (array)$external;
				foreach((array)$this->hidden1 as $key => $value) {
					$this->hiddenClean1[$this->make_clean_url($key)] = $value;
				}
				return $this->arrayNavigation;
			
		}
		else {
			return $this->arrayNavigation;
		}
	}
	public function arraySecondaryNavigation($admin = false) {
		//var_dump('admin', $admin, '---', $this->arraySecondaryNavigation);
		if($this->arraySecondaryNavigation == -10 || $admin == true) {
				$refs = array();
				$data = array();
				$options = false;
				$list = array();
				$sql = "SELECT parent_id, menutitle, id, options FROM ".DBTABLEPREFIX."content_pages WHERE secondary = 'yes' ORDER by orderingid";
				$run = $this->db_query($sql)or die($this->db->error());
				while($data = $this->db->fetchAssoc($run)) {
					$options = unserialize(stripcslashes($data['options']));
					//$thisref = &$refs[ $data['id'] ];
					if($options['show'] === 'show' || $options === false || $admin === true) {
						$thisref['id'] = $data['id'];
						$thisref['menutitle'] = $data['menutitle'];
						if(!empty($options['external'])) {
							$external[$thisref['id']] = $options['external'];
						}
						if ($data['parent_id'] == 0) {
							$list[$thisref['id']] = &$thisref;
						} else {
							$refs[ $data['parent_id'] ]['children'][ $thisref['id'] ] = &$thisref;
						}
					}
					if($options['show'] !== 'show' && $options !== false) {
						if(empty($options['external']))
							$list5[$data['menutitle']] = $data['id'];
					}
					$list2[$thisref['id']] = $data['menutitle'];
					$list3[$thisref['id']] = $this->make_clean_url($data['menutitle']);
					$list4[$thisref['id']] = $data['parent_id'];
				}
				$this->arraySecondaryNavigation = $list;
				$this->idLookup2 = $list2;
				$this->idLookup2clean = $list3;
				$this->childLookup2 = $list4;
				$this->hidden2 = (array) $list5;
				$this->external = $this->external + (array)$external;
				foreach((array)$this->hidden2 as $key => $value) {
					$this->hiddenClean2[$this->make_clean_url($key)] = $value;
				}
				return $this->arraySecondaryNavigation;
		}
		else {
			return $this->arraySecondaryNavigation;
		}
	}
	public function hiddenNavItems () {
		if($this->arraySecondaryNavigation == -10)
			$this->arraySecondaryNavigation();
		if(empty($this->arrayNavigation))
			$this->arrayNavigation();
		if($this->hidden == false)
			$this->hidden = (array)$this->hidden1 + (array)$this->hidden2;
		return $this->hidden;
	}
	public function makeLink ($href, $text = true, $class = '', $mode = 'id') {
		if($this->arraySecondaryNavigation == -10)
			$this->arraySecondaryNavigation();
		if(empty($this->arrayNavigation))
			$this->arrayNavigation();
		if($GLOBALS['cleanUrls'] == "Enabled") {
			if(SIMPLE_CLEAN_URLS)
				$url = sprintf(SIMPLE_CLEAN_URLS_FORMAT, $href, $this->idLookup($href, false, true), THEME_URL, $this->parentNavItems($href), CONTENT_SLUG);
			else
				$url = sprintf(CLEAN_URLS_FORMAT, $href, $this->idLookup($href, false, true), THEME_URL, $this->parentNavItems($href), CONTENT_SLUG);
		}
		else {
			$url = sprintf(UNCLEAN_URLS_FORMAT, $href, THEME_URL, $this->parentNavItems($href), CONTENT_SLUG);
		}
		if($text === true)
			$text = $this->idLookup($href);
		return sprintf('<a href="%s" class="%s">%s</a>', $url, $class, $text);
	}
	public function makeUrl ($id, $mode = 'id') {
		$GLOBALS['cleanUrls'] = $this->getSetting('Clean Urls');
		if($mode == 'id') {
			$v['id'] = $id;
			$v['menutitle'] = $this->idLookup($id);
		}
		elseif($mode == 'menutitle') {
			$v['menutitle'] = $id;
			$v['id'] = $this->idLookup($id, true);
		}
		if($GLOBALS['cleanUrls'] == "Enabled") {
			if(SIMPLE_CLEAN_URLS)
				$url = sprintf(SIMPLE_CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
			else
				$url = sprintf(CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
		}
		else {
			$url = sprintf(UNCLEAN_URLS_FORMAT, $v['id'], THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
		}
		return $url;
	}
	public function parentNavItemsFunc_child ($id) {
		$parent = $this->childLookup[$id];
		if(!is_array($r))
			$r = (array) $r;
		if($parent != '0') {
			//($parent, $this->idLookup($parent, false, true));
			array_push($r, $this->idLookup($parent, false, true));
			array_merge((array) $r, (array) $this->parentNavItemsFunc_child($parent));
			return $r;
		}
		else {
			return array_merge((array) $r, (array) $this->idLookup($id, false, true));
			//return (array) $r;
		}
	}
	public function parentNavItemsFunc ($id, $clear = true, $final = false) {
		if($clear == true) {
			$r = array();
		}
		if($this->arraySecondaryNavigation == -10)
			$this->arraySecondaryNavigation();
		if(empty($this->arrayNavigation))
			$this->arrayNavigation();
		if($this->childLookup == false)
			$this->childLookup = (array)$this->childLookup1 + (array)$this->childLookup2;
		$parent = $this->childLookup[$id];
		
		if($parent != '0') {
			//($parent, $this->idLookup($parent, false, true));
			array_push($r, $this->idLookup($parent, false, true));
			array_merge((array) $r, (array) $this->parentNavItemsFunc_child($parent));
		}
		else {
			return array_merge((array) $r, (array) $this->idLookup($id, false, true));
		}
		var_dump($id, $parent, $r);
		/*$r = array_reverse(removeBlanks($r));
		foreach($r as $key => $value) {
			if(is_array($value)) {
				$r[$key] = null;
			}
			elseif(substr_count($value, '/') > 0) {
				$x = array_reverse(removeBlanks(explode('/', $value)));
				unset($r[$key]);
				foreach($x as $valuez)
					array_push($r, '/',$valuez);
			}
		}*/
		return (array) $r;
	}
	public function buildParentTree_child ($id) {
		$r = '';
		$parent_id = $this->childLookup[$id];
		if(array_key_exists($id, $this->childLookup))
			$r = '|' . $this->buildParentTree_child($parent_id) . '|' . $this->idLookup($id, false, true);
		else 
			$r = '|' . $this->idLookup($id, false, true);
		//var_dump($id, $r);
			
		return $r;
	}
	public function buildParentTree ($id) {
		if($this->arraySecondaryNavigation == -10)
			$this->arraySecondaryNavigation();
		if(empty($this->arrayNavigation))
			$this->arrayNavigation();
		if($this->childLookup == false)
			$this->childLookup = (array)$this->childLookup1 + (array)$this->childLookup2;
		$r = '';
		//var_dump((array)$this->childLookup1 , (array)$this->childLookup2);
		$parent_id = $this->childLookup[$id];
		//var_dump($id,  $this->idLookup($id, false, true), $parent_id, array_key_exists($parent_id, $this->childLookup), $this->buildParentTree_child($parent_id));
		//echo "\n\n";
		if(array_key_exists($parent_id, $this->childLookup))
			$r = $this->buildParentTree_child($parent_id) . '|' . $this->idLookup($id, false, true);// + array($this->idLookup($id, false, true));
		else 
			$r = '|' . $this->idLookup($id, false, true);
		return (array) removeBlanks(explode('|', $r));
	}
	public function parentNavItems($id) {
		$q = $this->buildparentTree($id);
		return implode('/', $q);
		$r = $this->parentNavItemsFunc($id);
		$r = implode('/',(array) array_reverse((array) $r)).'/';
		return CONTENT_SLUG.'/'.ltrim($r,'/');
	}
	public function idLookup($str, $reverse = false, $clean = false, $hidden = false) {
		if($this->arraySecondaryNavigation == -10)
			$this->arraySecondaryNavigation();
		if(empty($this->arrayNavigation))
			$this->arrayNavigation();
		if($this->hidden == false)
			$this->hidden = (array)$this->hidden1 + (array)$this->hidden2;
		if($this->hiddenClean == false)
			$this->hiddenClean = (array)$this->hiddenClean1 + (array)$this->hiddenClean2;
		if($this->idLookup == false)
			$this->idLookup = (array)$this->idLookup1 + (array)$this->idLookup2;
		if($this->idLookupClean == false)
			$this->idLookupClean = (array)$this->idLookup1clean + (array)$this->idLookup2clean;
		if($hidden == true && array_key_exists($str, $this->hidden))
			return $this->hidden[$str];
		elseif($hidden == true && $clean == true && array_key_exists($str, $this->hiddenClean))
			return $this->hiddenClean[$str];
		elseif(array_key_exists((string) $str,(array) $this->idLookupClean) && $reverse == false && $clean == true)
			return $this->idLookupClean[$str];
		elseif(array_key_exists((string) $str, (array)$this->idLookup) && $reverse == false)
			return $this->idLookup[$str];
		elseif(in_array($str, (array) $this->idLookup) && $reverse == true && $clean == false)
			return array_search($str, $this->idLookup);
		elseif(in_array($str,(array) $this->idLookupClean) && $reverse == true && $clean == true)
			return array_search($str, $this->idLookupClean);
		else 
			return (array_key_exists((string) $str, $this->hidden) ? $this->hidden[$str] : false);
			
	}
	public function subPagesOf ($str, $a = "\n<ul class='subpagelist'>\n%s\n</ul>", $b = "\n\t<li><a href=\"%2\$s\">%1\$s</a></li>", $c = "\n\t<li>This page has no sub pages.</li>") {
		if($this->arraySecondaryNavigation == -10)
			$this->arraySecondaryNavigation();
		if(empty($this->arrayNavigation))
			$this->arrayNavigation();
		if(empty($this->childLookup))
			$this->childLookup = (array)$this->childLookup1 + (array)$this->childLookup2;	
		foreach($this->childLookup as $key => $value) {
			if($value == $str)
				$results[] = $key;
		}
		$each = '';
		$results = removeBlanks($results);
		if(!empty($results)) {
			foreach($results as $value) {
				$each .= sprintf($b, $this->idLookup($value, false, false), $this->makeUrl($value));
			}
		}
		else {
			$each = $c;
		}
		return sprintf($a, $each);
	}
	public function optionListFromArray($arr, $pre, $selected = "", $indent=0, $mother_run=true, $nameInValue = 0){
		$GLOBALS['cleanUrls'] = $this->getSetting('Clean Urls');
		foreach($arr as $k=>$v){
			// skip the baseval thingy. Not a real node.
			if($k == "__base_val") continue;
			
			if($k == "id" || $k == 'menutitle') continue;
			// determine the real value of this node.
			$show_val = ( is_array($v) ? $v["__base_val"] : $v );
	 
			if($k == "children") {
				$return .= $this->optionListFromArray($v, $pre, $selected, ($indent), false, $nameInValue);			
			}
			else {
				// show the actual node
				if($nameInValue == 1) {
					if($GLOBALS['cleanUrls'] == "Enabled") {
						if(SIMPLE_CLEAN_URLS)
							$url = sprintf(SIMPLE_CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
						else
							$url = sprintf(CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
						$return .= "\t".str_repeat("\t", $indent)."<option value='$url'";
					}
					else {
						$url = "\t".str_repeat("\t", $indent)."<option value='".sprintf(UNCLEAN_URLS_FORMAT, $v['id'], THEME_URL, $this->parentNavItems($v['id']))."'";
					}
				}
				else {
					$return .= "\t".str_repeat("\t", $indent)."<option value='".$pre.$v['id']."'";
				}
				if($selected != "") {
					if($selected == $v['id']) {
						$return .= " selected='selected'";
					}
				}
				$return .= ">".str_repeat("&#8212; ", $indent).stripcslashes($v['menutitle'])."</option>\n";
		 
				if(is_array($v)){
					// this is what makes it recursive, rerun for childs
					$return .= $this->optionListFromArray($v, $pre, $selected, ($indent+1), false, $nameInValue);
				}
			}
		}
		return $return;
	}
	public function buildNavArray($oneline = false) {
		return $this->arrayNavigation($oneline);
	}
	public function navigation (
		$root = "\n<ul id='ul-navigation'>\n%s\n</ul>\n",
		$child = "\n<ul class='ul-sub-navigation'>\n%s\n</ul>\n",
		$item = "\n\t<li><a href='%2\$s'>%1\$s</a></li>",
		$itemSelected = "\n\t<li class='selected'><a href='%2\$s'>%1\$s</a></li>",
		$itemHasChild = "\n\t<li><a href='%2\$s'>%1\$s</a>%3\$s</li>",
		$itemHasChildSelected = "\n\t<li class='selected'><a href='%2\$s'>%1\$s</a>%3\$s</li>",
		$isChild = false,
		$inputArray = array()
	) {
		if($this->navigation !== false && $isChild == false)
			$this->navigation = '';
		$GLOBALS['cleanUrls'] = $this->getSetting('Clean Urls');
		$GLOBALS['pageid'] = $_GET['page'];
		
		if($inputArray == array()) {
			$inputArray = $this->buildNavArray();
		}
		$x = 0;
		$r = '';
		$url = '';
		$count = count($inputArray);
		foreach($inputArray as $k=>$v) {
			if(is_array($v['children'])) {
				$sk = stripcslashes($v['menutitle']);
				if(array_key_exists($v['id'], $this->external)) {
					$url = $this->external($v['id']);
				}
				elseif($GLOBALS['cleanUrls'] == "Enabled") {
					if(SIMPLE_CLEAN_URLS)
						$url = sprintf(SIMPLE_CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
					else
						$url = sprintf(CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
				}
				else {
					$url = sprintf(UNCLEAN_URLS_FORMAT, $v['id'], THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
				}
				if($GLOBALS['pageid'] == $v['id']) {
					$children = $this->navigation($root, $child, $item, $itemSelected, $itemHasChild, $itemHasChildSelected, true,$v['children']);
					$r .= sprintf($itemHasChildSelected, $sk, $url, $children);	
				}
				else {
					$children = $this->navigation($root, $child, $item, $itemSelected, $itemHasChild, $itemHasChildSelected, true,$v['children']);
					$r .= sprintf($itemHasChild, $sk, $url, $children);	
				}
			}
			else {
				if(array_key_exists($v['id'], $this->external)) {
					$url = $this->external[$v['id']];
				}
				elseif($GLOBALS['cleanUrls'] == "Enabled") {
					if(SIMPLE_CLEAN_URLS)
						$url = sprintf(SIMPLE_CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
					else
						$url = sprintf(CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
				}
				else {
					$url = sprintf(UNCLEAN_URLS_FORMAT, $v['id'], THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
				}
				if($GLOBALS['pageid'] == $v['id']) {
					$r .= sprintf($itemSelected, stripcslashes($v['menutitle']), $url); 
				}
				else {
					$r .= sprintf($item, stripcslashes($v['menutitle']), $url); 				
				}
				$x++;
				if(ltrim($x, '0') == (string) $count) {
					if($isChild === true)
						return sprintf($child, $r, '');
					else
						return sprintf($root, $r, '');
				}
			}
		}
		if($isChild === true) {
			return sprintf($child, $r);
		}
		else {
			$this->navigation .= sprintf($root, $r);
		}
		return $this->navigation;
	}
	public function secondary_navigation (
		$root = "\n<ul id='ul-secondary-navigation'>\n%s\n</ul>\n",
		$child = "\n<ul class='ul-sub-navigation'>\n%s\n</ul>\n",
		$item = "\n\t<li><a href='%2\$s'>%1\$s</a></li>",
		$itemSelected = "\n\t<li class='selected'><a href='%2\$s'>%1\$s</a></li>",
		$itemHasChild = "\n\t<li><a href='%2\$s'>%1\$s</a>%3\$s</li>",
		$itemHasChildSelected = "\n\t<li class='selected'><a href='%2\$s'>%1\$s</a>%3\$s</li>",
		$isChild = false,
		$inputArray = array()
	) {
		if($this->secondary_navigation !== false && $isChild == false)
			$this->secondary_navigation = '';
		$GLOBALS['cleanUrls'] = $this->getSetting('Clean Urls');
		$GLOBALS['pageid'] = $_GET['page'];
		
		if($inputArray == array()) {
			$inputArray = $this->arraySecondaryNavigation();
		}
		$x = 0;
		$r = '';
		$url = '';
		$count = count($inputArray);
		foreach($inputArray as $k=>$v) {
			if(is_array($v['children'])) {
				$sk = stripcslashes($v['menutitle']);
				if(array_key_exists($v['id'], $this->external)) {
					$url = $this->external($v['id']);
				}
				elseif($GLOBALS['cleanUrls'] == "Enabled") {
					if(SIMPLE_CLEAN_URLS)
						$url = sprintf(SIMPLE_CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
					else
						$url = sprintf(CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
				}
				else {
					$url = sprintf(UNCLEAN_URLS_FORMAT, $v['id'], THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
				}
				if($GLOBALS['pageid'] == $v['id']) {
					$children = $this->secondary_navigation($root, $child, $item, $itemSelected, $itemHasChild, $itemHasChildSelected, true,$v['children']);
					$r .= sprintf($itemHasChildSelected, $sk, $url, $children);	
				}
				else {
					$children = $this->secondary_navigation($root, $child, $item, $itemSelected, $itemHasChild, $itemHasChildSelected, true,$v['children']);
					$r .= sprintf($itemHasChild, $sk, $url, $children);	
				}
			}
			else {
				if(array_key_exists($v['id'], $this->external)) {
					$url = $this->external[$v['id']];
				}
				elseif($GLOBALS['cleanUrls'] == "Enabled") {
					if(SIMPLE_CLEAN_URLS)
						$url = sprintf(SIMPLE_CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
					else
						$url = sprintf(CLEAN_URLS_FORMAT, $v['id'], $this->make_clean_url($v['menutitle']), THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
				}
				else {
					$url = sprintf(UNCLEAN_URLS_FORMAT, $v['id'], THEME_URL, $this->parentNavItems($v['id']), CONTENT_SLUG);
				}
				if($GLOBALS['pageid'] == $v['id']) {
					$r .= sprintf($itemSelected, stripcslashes($v['menutitle']), $url); 
				}
				else {
					$r .= sprintf($item, stripcslashes($v['menutitle']), $url); 				
				}
				$x++;
				if(ltrim($x, '0') == (string) $count) {
					if($isChild === true)
						return sprintf($child, $r, '');
					else
						return sprintf($root, $r, '');
				}
			}
		}
		if($isChild == true) {
			return sprintf($child, $r);
		}
		else {
			$this->secondary_navigation .= sprintf($root, $r);
		}
		return $this->secondary_navigation;
	}
	public function static_content ($editable, $default, $textOnly = '') {
		$GLOBALS['cleanUrls'] = $this->getSetting('Clean Urls');
		$GLOBALS['pageid'] = $_GET['page'];
		if(isset($this->staticContent[$editable])) {
			$rec['content'] = $this->staticContent[$editable]['content'];
		}
		else {
			$sql = "INSERT INTO ".DBTABLEPREFIX."content_template (name, content, template, textOnly) VALUES ('".sanitize_sql_string($editable)."', '".sanitize_sql_string($default)."', '".$this->getSetting('Theme')."', '".sanitize_sql_string($textOnly)."')";
			$run = $this->db_query($sql) or die($this->db->error());
			$rec['content'] = $default;
			$row[$editable] = array(
				'content' => stripslashes($default),
				'name' => $editable,
				'textOnly' => $textOnly
			);
			$this->staticContent[$editable] = $row[$editable];
		}
		$this->themeStaticContent[$editable] = $this->staticContent[$editable];
		$r = stripcslashes($rec['content']);
		return $r;
	}
	public function arr_diff($a1,$a2){
		$ar = array();
		foreach ($a2 as $k => $v) {
			if (!is_array($v)) {
				if ($v !== $a1[$k])
					$ar[$k] = $v;
			}else{
				if ($arr = $this->arr_diff($a1[$k], $a2[$k]))
					$ar[$k] = $arr;
			}
		}
		return $ar;
	}
	public function cleanStaticContentTable () {
		$deleteItems = array_diff_assoc((array) $this->staticContent, (array) $this->themeStaticContent);
		foreach($deleteItems as $key => $value) {
			$sql = "DELETE FROM ".DBTABLEPREFIX."content_template WHERE id = '{$value['id']}'";
			$run = $this->db_query($sql) or die($this->db->error());
		}
	}
	public function buildNavigation () {
		
	}
}
?>